{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "from ObjectTracking.deep_sort_tracker import DeepSortTracker\n",
    "from utilities import constants\n",
    "from utilities import helper\n",
    "from threads.ImageInput.WebcamThread import WebcamThread\n",
    "from threads.Predictor.PredictorImage import PredictorImage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Starting Webcam Thread\n"
     ]
    }
   ],
   "source": [
    "# Run the webcam thread\n",
    "thread_image = WebcamThread('Webcam Thread',1)\n",
    "thread_image.start()\n",
    "image_data = thread_image.image_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loading Model File: /home/watopedia/github_projects/aipod-main/nnModels/coco/frozen_inference_graph.pb\n",
      "Finished Loading Model\n",
      "Starting coco\n"
     ]
    }
   ],
   "source": [
    "thread_coco = PredictorImage('coco',\n",
    "                       constants.CKPT_COCO,\n",
    "                       constants.LABELS_COCO,\n",
    "                       image_data,\n",
    "                       score_thresh = 0.5,\n",
    "                       WITH_TRACKER = False)\n",
    "thread_coco.start()\n",
    "thread_coco.continue_predictor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "tracker = DeepSortTracker()\n",
    "#tracker.min_confidence = 0.1\n",
    "#tracker.nms_max_overlap = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Run the main loop\n",
    "while True:\n",
    "    # Grab the image and convert from RGB -> BGR\n",
    "    image_np = thread_image.image_data.image_np.copy()[:,:,::-1]\n",
    "    output_data = thread_coco.output_data\n",
    "    output_data = tracker.run(output_data,image_np)\n",
    "    image_np = helper.drawDetectedBBs(image_np.copy(),\n",
    "                                 output_data,\n",
    "                               score_thresh = 0.1)\n",
    "\n",
    "    \n",
    "    \n",
    "    frameName = 'Main Frame'\n",
    "    cv2.namedWindow(frameName, cv2.WND_PROP_FULLSCREEN)\n",
    "    cv2.setWindowProperty(frameName,cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)\n",
    "    cv2.imshow(frameName, image_np)\n",
    "    key = cv2.waitKey(10)\n",
    "    if key == ord('q'):\n",
    "        break\n",
    "cv2.destroyAllWindows()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
